/* These steps must be completed before script is run.
1. Service Activation
2. Stop/Start CCM IP
3. Service Parameters ---> Database Layer ---> MAXAXLWRITESAMINUTE to 200+
3. Enterprise Parameters
4. Service Parameters
5. Media Termination Point
6. Annunciator
7. Change route group distribution
*/

public class ConfigCPNmain
{

	private static String validTrunkIP ( String ip ) {
			
			try { 
		        if ( ip == null || ip.isEmpty()) { 
		            return null ; 
		        } 
		        
		        String[] parts = ip.split( "\\." ) ; 
		        if ( parts.length != 4 ) { 
		            return null ; 
		        } 
		 
		        for ( String s : parts ) { 
		            int i = Integer.parseInt( s ) ; 
		            if ( (i < 0) || (i > 255 ) ) { 
		                return null ; 
		            } 
		        }
		        
		        int counter = 0 ; 
		        for( int i = 0 ; i < ip.length() ; i++ ) { 
		            if( ip.charAt(i) == '.' ) { 
		                counter++ ; 
		            }  
		        }
		        if( counter != 3 ) return null ;

		        return ip ; 
		    } catch ( NumberFormatException nfe ) { 
		        return null ; 
		    } 
		}
    
    
        public void main2(){}
	public void main2( String server , String user , String pass , String number , String type , String Classification , String[] TrunkIPs , String[] TrunkIDs , String[] TrunkTypes ) throws InterruptedException
	{
		int i ;
		String hostInput = server ;
		String username = user ;
		String password = pass ;
		String nodeInput = number ;
		String classification = Classification ;
		String[] trunk = { null , null , null , null , null , null , null , null } ;
                String[] remoteDevice = { null , null , null , null , null , null , null , null } ;
                String[] node = { null , null , null , null , null , null , null , null } ;
                String trash = null;
                String octet[] = { null , null , null , null } ;
		octet = hostInput.split("\\.") ;
		String firstThree = ( octet[0] + "." + octet[1] + "." + octet[2] ) ;
                
                String[] routePartitionNameSiprArray = {
				"SET_FO_Class_A","SET_F_Class_A","SET_I_Class_A","SET_P_Class_A","SET_R_Class_A",
				"SET_FO_Class_B","SET_F_Class_B","SET_I_Class_B","SET_P_Class_B","SET_R_Class_B",
				"SET_FO_Class_C","SET_F_Class_C","SET_I_Class_C","SET_P_Class_C","SET_R_Class_C",
				"BVTC_Partition","Class_A_Routes","Class_B_Routes","Class_C_Routes","BLOCK"
		};
		
		String[] routePartitionDescSiprArray = {
				"Class A Flash Override Precedence","Class A Flash Precedence","Class A Immediate Precedence",
				"Class A Priority Precedence","Class A Routine Precedence","Class B Flash Override Precedence",
				"Class B Flash Precedence","Class B Immediate Precedence","Class B Priority Precedence",
				"Class B Routine Precedence","Class C Flash Override Precedence","Class C Flash Precedence",
				"Class C Immediate Precedence","Class C Priority Precedence","Class C Routine Precedence",
				"BVTC Hunt Stop","DRSN VoSIP Access","Inter-Theater VoSIP Access","Intra-Theater VoSIP Access","BLOCK Precedence"
		};
                
                String[] cssNameSiprArray = {
                                "Class_A_Routes","Class_B_Routes","Class_C_Routes"
                };
             
                String[] translationPatternArray = {
                    "90.!","91.!","92.!","93.!","94.!"
                };
                
                String[] translationPatternDescArray = {
                    "Set Flash Override Precedence","Set Flash Precedence","Set Immediate Precedence","Set Priority Precedence",
                    "Set Routine Precedence"
                };
                
                String[] translationPatternPrecArray = {
                    "Flash Override","Flash","Immediate","Priority","Routine"
                };
                
                
                
                for(i=0 ; i < 8 ; i++){
                    trunk[i] = TrunkIPs[i] ;
                    remoteDevice[i] = TrunkTypes[i] ;
                    node[i] = TrunkIDs[i] ;
                }

                
                System.out.println( hostInput + "\n" + username + "\n" + password + "\n" + nodeInput + "\n" + classification + "\n" + firstThree);

	
		ConfigCPNclass cpn = new ConfigCPNclass(hostInput, firstThree, nodeInput, username, password);
		
                cpn.updateServiceParameterMaxAXLWritesPerMinute();
		
                System.out.println( "Now Applying Max AXL Writes.  This will take 1 Minute.");
                Thread.sleep(60000);
                System.out.println( "Max AXL Writes application complete.  Continuing with system configuration.") ;
                
                cpn.addCallManager();
                
                cpn.updateServiceParameterDSCPForSCCPPhoneConfig();
		
		cpn.updateServiceParameterDSCPForCm2Dvce();
		
		cpn.updateServiceParameterMLPPIndicationStatus();
		
		cpn.updateServiceParameterTimerT302_msec();
		
		cpn.updateServiceParameterTimerT305_msec();
		
		cpn.updateServiceParameterToSendH225UserInfoMsg();
		
		cpn.updateServiceParameterCallClassification();
		
		cpn.updateServiceParameterEnableLocationMLPP();
		
		cpn.updateServiceParameterMaxAdHocConference();
		
		cpn.updateServiceParameterMaxMeetMeConferenceUnicast();
		
		cpn.updateServiceParameterDSCPForVideoCalls();
		
		cpn.updateServiceParameterDSCPforICCP();
		
		cpn.add711Region();
		
		cpn.add729Region();
		
		cpn.add711DevicePool();
		
		cpn.add729DevicePool();
		
                cpn.getDevicePool();
                
		cpn.updateMTPSOFTsql();
                
                cpn.updateMTPIOSsql();
                
                cpn.updateANNsql();
         
		cpn.addTranscoder();
		
		cpn.addConferenceBridge();
		
		cpn.addMOHServer();
		
		cpn.SQLupdateAnnunciator();
		
		cpn.addCFBMediaResourceGroup();
		
		cpn.addMOHMediaResourceGroup();
		
		cpn.addXCodeMediaResourceGroup();
		
		cpn.addMTPIOSMediaResourceGroup();
		
		cpn.addMTPSOFTMediaResourceGroup();
		
		cpn.addANNMediaResourceGroup();
		
		cpn.add711MediaResourceList();
		
		cpn.add729MediaResourceList();
		
		cpn.addTDMALocation();
		
		cpn.addFDMALocation();
		
		cpn.addLOSLocation();
                
                
                if (classification.equals("N"))
                    {
		
                        cpn.add9094RoutePartition();

                        cpn.addBlockRoutePartition();

                        cpn.addSetFRoutePartition();

                        cpn.addSetFORoutePartition();

                        cpn.addSetIRoutePartition();

                        cpn.addSetPRoutePartition();

                        cpn.addSetRRoutePartition();

                        cpn.addPrecFOCSS();

                        cpn.addPrecFCSS();

                        cpn.addPrecICSS();

                        cpn.addPrecPCSS();

                        cpn.addPrecRCSS();

                        cpn.add9094CSS();

                        cpn.addTransPattern1();

                        cpn.addTransPattern2();

                        cpn.addTransPattern3();

                        cpn.addTransPattern4();

                        cpn.addTransPattern5();

                        cpn.addTransPattern6();

                        cpn.addTransPattern7();

                        cpn.addTransPattern8();

                        cpn.addTransPattern9();
                    }
		
		if (classification.equals("S"))
                    {
                        for( i=0; i < 20; i++)
                            {
                            cpn.addSIPRRoutePartitions(routePartitionNameSiprArray[i], routePartitionDescSiprArray[i]);
                            }
                        cpn.addClassAFlashOverrideCSS();
                        cpn.addClassAFlashCSS();
                        cpn.addClassAImmediateCSS();
                        cpn.addClassAPriorityCSS();
                        cpn.addClassARoutineCSS();
                        cpn.addClassBFlashOverrideCSS();
                        cpn.addClassBFlashCSS();
                        cpn.addClassBImmediateCSS();
                        cpn.addClassBPriorityCSS();
                        cpn.addClassBRoutineCSS();
                        cpn.addClassCFlashOverrideCSS();
                        cpn.addClassCFlashCSS();
                        cpn.addClassCImmediateCSS();
                        cpn.addClassCPriorityCSS();
                        cpn.addClassCRoutineCSS();
                        cpn.addClassARoutesCSS();
                        cpn.addClassBRoutesCSS();
                        cpn.addClassCRoutesCSS();
                        
                        int k = 0;                                
                        for(i=0 ; i<3 ; i++ ) { 
                            for(int j=0 ; j<5 ; j++ ) {
                                cpn.addTransPatternSIPR( translationPatternArray[j],translationPatternDescArray[j],routePartitionNameSiprArray[k],translationPatternPrecArray[j],cssNameSiprArray[(i)], "false", "No Error") ;
                                k++ ;
                            } 
   
                        }
                        
                        cpn.addTransPatternSIPR("9[0-4].!", "Block Unauthorized Precedence", "Block", "Default", "", "true", "Precedence Level Exceeded");
			
                    }
                
		
		
		for( i = 0 ; i < 8 ; i++){
                    if( (remoteDevice[i].equals("JNN"))) { //&& (validTrunkIP(remoteDevice[i]) != null )) {
                            String SRST1[] = { null , null , null , null } ;
                            SRST1 = TrunkIPs[0].split("\\.") ;
                            int lastOctet1 = Integer.parseInt(SRST1[3]) + 1 ;
                            String TrunkSRST = ( SRST1[0] + "." + SRST1[1] + "." + SRST1[2] + "." + lastOctet1 ) ;
                            if (classification.equals("N")){
                                cpn.addH323Trunk(trunk[i], remoteDevice[i], node[i], classification, "PREC_FO");
                                cpn.addH323TrunkSRST(TrunkSRST, remoteDevice[i], node[i], classification, "PREC_FO");
                            }
                            else {
                                cpn.addH323Trunk(trunk[i], remoteDevice[i], node[i], classification, "Class_A_Flash_Override");
                                cpn.addH323TrunkSRST(TrunkSRST, remoteDevice[i], node[i], classification, "Class_A_Flash_Override");
                            }
                            cpn.addRouteGroup(remoteDevice[i], node[i], classification);
                            cpn.addRouteList(remoteDevice[i], node[i]);
                            cpn.addRoutePatternJNN(remoteDevice[i], node[i]);
                            cpn.addRoutePattern1(remoteDevice[i], node[i]);
                            cpn.addRoutePattern2(remoteDevice[i], node[i]);
                    }
                    
		
                    if( (remoteDevice[i].equals("CPN"))) {// && (validTrunkIP(remoteDevice[i]) != null )) {
                         
                        if (classification.equals("N")){
                                cpn.addH323Trunk(trunk[i], remoteDevice[i], node[i], classification, "PREC_FO");                                
                            }
                            else {
                                cpn.addH323Trunk(trunk[i], remoteDevice[i], node[i], classification, "Class_A_Flash_Override");
                            }
                        cpn.addRouteGroup(remoteDevice[i], node[i], classification);
                        cpn.addRouteList(remoteDevice[i], node[i]);
                        cpn.addRoutePatternBCP(remoteDevice[i], node[i]);
                        
                    }
                    
                    if( remoteDevice[i].equals("SSS") || remoteDevice[i].equals("UHN") || remoteDevice[i].equals("Select:")) {}
                   
                }
	}
}